home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / exec / copymemquick.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  2KB  |  100 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: copymemquick.c,v 1.4 1996/08/13 13:55:59 digulla Exp $
  4.     $Log: copymemquick.c,v $
  5.     Revision 1.4  1996/08/13 13:55:59  digulla
  6.     Replaced __AROS_LA by __AROS_LHA
  7.     Replaced some __AROS_LH*I by __AROS_LH*
  8.     Sorted and added includes
  9.  
  10.     Revision 1.3  1996/08/01 17:41:07  digulla
  11.     Added standard header for all files
  12.  
  13.     Desc:
  14.     Lang:
  15. */
  16. #include <aros/libcall.h>
  17.  
  18. /*****************************************************************************
  19.  
  20.     NAME */
  21.     #include <exec/types.h>
  22.  
  23.     __AROS_LH3I(void, CopyMemQuick,
  24.  
  25. /*  SYNOPSIS */
  26.     __AROS_LHA(APTR,  source, A0),
  27.     __AROS_LHA(APTR,  dest,   A1),
  28.     __AROS_LHA(ULONG, size,   D0),
  29.  
  30. /*  LOCATION */
  31.     struct ExecBase *, SysBase, 105, Exec)
  32.  
  33. /*  FUNCTION
  34.     Copy some longwords from one destination in memory to another using
  35.     a fast copying method.
  36.  
  37.     INPUTS
  38.     source - Pointer to source area (must be ULONG aligned)
  39.     dest   - Pointer to destination (must be ULONG aligned)
  40.     size   - number of bytes to copy (must be a multiple of sizeof(ULONG))
  41.  
  42.     RESULT
  43.  
  44.     NOTES
  45.     The source and destination area are not allowed to overlap.
  46.  
  47.     EXAMPLE
  48.  
  49.     BUGS
  50.  
  51.     SEE ALSO
  52.     CopyMem()
  53.  
  54.     INTERNALS
  55.  
  56.     HISTORY
  57.     22-10-95    Created by M. Fleischer
  58.  
  59. ******************************************************************************/
  60. {
  61.     __AROS_FUNC_INIT
  62.  
  63.     ULONG low,high;
  64.  
  65.     /* Calculate number of ULONGs to copy */
  66.     size/=sizeof(ULONG);
  67.  
  68.     /*
  69.     To minimize the loop overhead I copy more than one (eight) ULONG per
  70.     iteration. Therefore I need to split size into size/8 and the rest.
  71.     */
  72.     low =size&7;
  73.     high=size/8;
  74.  
  75.     /* Then copy for both parts */
  76.     if(low)
  77.     do
  78.         *((ULONG *)dest)++=*((ULONG *)source)++;
  79.     while(--low);
  80.  
  81.     /*
  82.     Partly unrolled copying loop. The predecrement helps the compiler to
  83.     find the best possible loop. The if is necessary to do this.
  84.     */
  85.     if(high)
  86.     do
  87.     {
  88.         *((ULONG *)dest)++=*((ULONG *)source)++;
  89.         *((ULONG *)dest)++=*((ULONG *)source)++;
  90.         *((ULONG *)dest)++=*((ULONG *)source)++;
  91.         *((ULONG *)dest)++=*((ULONG *)source)++;
  92.         *((ULONG *)dest)++=*((ULONG *)source)++;
  93.         *((ULONG *)dest)++=*((ULONG *)source)++;
  94.         *((ULONG *)dest)++=*((ULONG *)source)++;
  95.         *((ULONG *)dest)++=*((ULONG *)source)++;
  96.     }while(--high);
  97.     __AROS_FUNC_EXIT
  98. } /* CopyMemQuick */
  99.  
  100.